package com.winit.openapi.claim.validator;

import com.alibaba.fastjson.JSONObject;
import com.winit.openapi.util.ValidateUtil;

public class ClaimOrderValidator {

    public static void validateClaimOrder(JSONObject input) {

        ValidateUtil.validNotNull(input, "trackingNo");
        ValidateUtil.validMaxLength(input, "trackingNo", 64, true);

        ValidateUtil.validNotNull(input, "type");
        ValidateUtil.validMaxLength(input, "type", 10, true);
        // type只允许LS|BK
        ValidateUtil.validByRegex(input, "type", "LS|BK|ls|bk", false);

        ValidateUtil.validNotNull(input, "quantity");
        ValidateUtil.validNumberBiggerThanZero(input, "quantity");

        ValidateUtil.validNotNull(input, "totalAmount");
        ValidateUtil.validNumberBiggerThanZero(input, "totalAmount");

        ValidateUtil.validNotNull(input, "lastMileAmount");
        ValidateUtil.validNumberBiggerThanZero(input, "lastMileAmount");

        ValidateUtil.validNotNull(input, "describeEN");
        ValidateUtil.validMaxLength(input, "describeEN", 250, true);

        ValidateUtil.validNotNull(input, "reason");
        ValidateUtil.validMaxLength(input, "reason", 250, true);

        ValidateUtil.validNotNull(input, "valueOfProofURL");
        ValidateUtil.validMaxLength(input, "valueOfProofURL", 250, true);

        ValidateUtil.validNotNull(input, "cargoPhotosURL");
        ValidateUtil.validMaxLength(input, "cargoPhotosURL", 250, true);

    }

    public static void validateClaimOrderList(JSONObject input) {
        ValidateUtil.validNotNull(input, "customerCode");
        ValidateUtil.validMaxLength(input, "customerCode", 64, true);
        if (input.containsKey("pageParams")) {
            Object object = input.get("pageParams");
            JSONObject page = (JSONObject) object;
            ValidateUtil.validNumberBiggerThanZero(page, "pageNum");
            ValidateUtil.validNumberBiggerThanZero(page, "pageSize");
        }

    }

    public static void main(String[] args) {
        JSONObject json1 = null;
        net.sf.json.JSONObject josn2 = null;
        String str = "{\"userId\":\"15\",\"userName\": null,\"address:\":\"null\",\"age\":\"\"}";
        json1 = JSONObject.parseObject(str);
        josn2 = net.sf.json.JSONObject.fromObject(str);
        System.err.println("fastJSON：" + json1);
        System.err.println("net.sf.json:" + josn2);
    }
}
